package com.hua.word;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.data.HyperlinkTextRenderData;
import com.deepoove.poi.data.TextRenderData;
import com.hua.utils.Result;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Component
public class wordTemp {

    public Result word(){
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
        Map<String,Object> map = new HashMap<>();
        map.put("test00","这是标题");
        map.put("author", new TextRenderData("000000", "Sayi"));
        map.put("link", new HyperlinkTextRenderData("website", "http://deepoove.com"));
        map.put("anchor", new HyperlinkTextRenderData("anchortxt", "anchor:appendix1"));
        XWPFTemplate template = XWPFTemplate.compile("./src/main/java/com/hua/word/p.docx").render(map);
        try {
            FileOutputStream out = new FileOutputStream("./src/main/java/com/hua/word/p-test.docx");
            template.writeAndClose(out);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Result.ok();
    }
}
